package io.hots.config;

import lombok.Data;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yueshibin@cetcbigdata.com
 * @date 2022/6/17 8:23 下午
 */

@Configuration
@Data
public class RabbitMQConfig {
    /**
     * 交换机
     */
    private String scanCodeExchange="scan_code.exchange";

    @Bean
    public Exchange scanCodeExchange(){
        return new TopicExchange(scanCodeExchange,true,false);
    }

    /**
     * 用户队列
     */
    private String scanCodeUserQueue = "scan_code.user.queue";

    /**
     * 创建user队列
     */
    @Bean
    public Queue scanCodeUserQueue(){
        return new Queue(scanCodeUserQueue,true,false,false);
    }

    /**
     * 发送消息的routingKey
     */
    private String scanCodeRoutingKey = "scan_code.user.venue.routing_key";

    /**
     * 进入user队列的routingKey通配符
     */
    private String scanCodeUserRoutingKey = "scan_code.user.*.routing_key";

    /**
     * 绑定user队列与交换机
     */
    @Bean
    public Binding scanCodeUserBinding(){
        return new Binding(scanCodeUserQueue, Binding.DestinationType.QUEUE,scanCodeExchange,scanCodeUserRoutingKey,null);
    }
}
